import 'package:auto_size_text_field/auto_size_text_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter_soundmagus/page/delay/delay_controller.dart';
import 'package:flutter_soundmagus/util/util.dart';
import 'package:flutter_soundmagus/widget/eq/eq.dart';
import 'package:flutter_soundmagus/widget/widget.dart';
import 'package:get/get.dart';

class DelayItem extends GetView<DelayController> {
  final int index;
  final FocusNode focusNode;
  DelayItem({Key? key, required this.index, required this.focusNode}) : super(key: key);

  DelayItemController get c => Get.find<DelayController>().delayItemControllers[index];

  @override
  Widget build(BuildContext context) {
    return Stack(children: [
      Obx(() => CircularSlider(
            min: 0,
            max: 8,
            initialValue: c.delay.value,
            enable: controller.selectCH.value == index,
            onChange: (v) {
              controller.setChannel(index);
              c.updateDelay(v);
            },
            onIncrease: c.increaseDelay,
            onDecrease: c.decreaseDelay,
            decreaseOffset: Offset(0, 15),
            increaseOffset: Offset(0, 15),
            innerWidget: (v) => Align(
              alignment: Alignment.bottomCenter,
              child: Padding(
                padding: const EdgeInsets.only(bottom: 20),
                child: TextButton(
                    onPressed: controller.nextUnit,
                    child: Obx(() => Text(
                          '${c.delayString(unitType: controller.unit.value) + controller.unit.value.name}',
                          style: TextStyle(color: Colors.white),
                        ))),
              ),
            ),
          )),
      Align(
        alignment: Alignment.topCenter,
        child: Obx(() => Padding(
              padding: const EdgeInsets.only(top: 20),
              child: ZFButton(
                onPressed: () => controller.setChannel(index),
                title: DataMng.shared.chNames[index].value,
                size: Size(60.w, 20.w),
                selected: controller.selectCH.value == index,
                borderColor: controller.selectCH.value == index
                    ? Theme.of(context).primaryColor
                    : Theme.of(context).textTheme.bodyLarge!.color!,
                style: TextStyle(fontSize: 10),
              ),
            )),
      )
    ]);
  }
}
